#pragma once

#include <iostream>
#include <string>
#include <fstream>
#include <boost/algorithm/string.hpp>
#include "cppjieba/Jieba.hpp"


namespace Util
{
    class FileUtil
    {
    public:
        static bool Read(const std::string &path, std::string *out)
        {
            std::ifstream inf(path, std::ios::in);
            if (!inf.is_open()) // 没有打开文件
            {
                std::cerr << "open file " << path << "error" << std::endl;
                return false;
            }
            std::string cont;
            while (std::getline(inf, cont))
            {
                *out += cont;
            }

            inf.close();
            return true;
        }
    };
    class StringUtil
    {
    public:
        static void CutString(const std::string &line, std::vector<std::string> *out, const std::string &sep)
        {
            // size_t pos1 = line.find(sep);
            // std::string title = line.substr(0, pos1);
            // size_t pos2 = line.find(sep, pos1 + 1);
            // std::string content = line.substr(pos1 + 1, pos2);
            // size_t pos3 = line.find("\n");
            // std::string url = line.substr(pos2 + 1);

            // out->push_back(title);
            // out->push_back(content);
            // out->push_back(url);

            // 可以使用这个boost split
            boost::split(*out, line, boost::is_any_of(sep), boost::token_compress_on);
        }
    };

    const char *const DICT_PATH = "./dict/jieba.dict.utf8";
    const char *const HMM_PATH = "./dict/hmm_model.utf8";
    const char *const USER_DICT_PATH = "./dict/user.dict.utf8";
    const char *const IDF_PATH = "./dict/idf.utf8";
    const char *const STOP_WORD_PATH = "./dict/stop_words.utf8";

    class JiebaUtil
    {
    private:
        static cppjieba::Jieba jieba;

    public:
        static void Cutforstring(const std::string &s, std::vector<std::string> *out)
        {
            jieba.CutForSearch(s, *out);
        }
    };

    cppjieba::Jieba JiebaUtil::jieba(DICT_PATH, HMM_PATH, USER_DICT_PATH, IDF_PATH, STOP_WORD_PATH);
};
